package com.movitech.mobile.cz.base.modules.activiti.service;

import com.movitech.mobile.cz.base.modules.activiti.dao.AProcessConfigMapper;
import com.movitech.mobile.cz.base.modules.activiti.entity.AProcessConfig;
import com.movitech.mobile.cz.base.modules.activiti.entity.AProcessConfigExample;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AProcessConfigService {
    protected Logger logger = LoggerFactory.getLogger(getClass());

	@Autowired
	private AProcessConfigMapper aProcessConfigMapper;
	
	/***
	 * 获取Activiti流程配置对象列表
	 * @return
	 */
    public List<AProcessConfig> getAllAProcessConfigList() {
    	AProcessConfigExample filter = new AProcessConfigExample();
    	filter.createCriteria().andDelFlagEqualTo(0);
    	return aProcessConfigMapper.selectByExample(filter);
    }
    
	/***
	 * 根据id，获取Activiti流程配置对象
	 * @param id
	 * @return
	 */
    public AProcessConfig getAProcessConfigById(String id) {
    	AProcessConfig aProcessConfig = null;
    	if(StringUtils.isNotEmpty(id)){
    		aProcessConfig = aProcessConfigMapper.selectByPrimaryKey(id);
    	}
    	return aProcessConfig;
    }

    /***
     * 保存AProcessConfig对象
     * @param aProcessConfig
     */
    public void saveAProcessConfig(AProcessConfig aProcessConfig) {
    	aProcessConfigMapper.insertSelective(aProcessConfig);
    }
    
    /***
     * 更新AProcessConfig对象
     * @param aProcessConfig
     */
    public void updateAProcessConfig(AProcessConfig aProcessConfig) {
    	aProcessConfigMapper.updateByPrimaryKeySelective(aProcessConfig);
    }

	/***
	 * 根据采购方式，获取Activiti流程配置对象 并获取最新发布日期的一个
	 * @param type
	 * @return
	 */
	public AProcessConfig getAProcessConfigByProcessTypeAndDelopTime(Integer type) {
		return aProcessConfigMapper.selectByProcessTypeAndDelopTime(type);
	}
    
    
}
